<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="110px"
    >
      <el-form-item label="用户" prop="userAccount">
        <el-input
          v-model="queryParams.userAccount"
          placeholder="请输入用户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交账号" prop="submitAccount">
        <el-input
          v-model="queryParams.submitAccount"
          placeholder="请输入账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
        </el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="UserUploadTaskList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="设备编号" align="center" prop="orderSn" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户账号" align="center" prop="account" />
      <el-table-column label="提交账号" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.detailList">
            <p v-for="(itemde, indexde) in scope.row.detailList" :key="indexde">
              {{ itemde.qq }}
            </p>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-help"
            @click="details(scope.row)"
            >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="" :visible.sync="outerVisible" width="1200px">
      <el-dialog
        :title="title"
        :visible.sync="open"
        width="800px"
        append-to-body
        @close="cancel"
      >
        <el-form ref="formRef" :model="form" label-width="80px">
          <el-form-item
            label=""
            prop="remark"
            :rules="{
              required: true,
              message: '请输入备注',
              trigger: 'blur',
            }"
          >
            <el-input
              type="textarea"
              placeholder="请输入内容"
              maxlength="150"
              v-model="form.remark"
              show-word-limit
              :autosize="{ minRows: 6, maxRows: 6 }"
            >
            </el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submit">{{ handBt }}</el-button>
            <el-button @click="cancel">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>

      <el-table
        v-loading="loading"
        :data="creativeOrderdetaillist"
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="账号" align="center" prop="qq" />
        <el-table-column label="密码" align="center" prop="qqPassword" />
        <el-table-column label="提交信息" align="center">
          <template slot-scope="scope">
            <div>
              <span>姓名：{{ scope.row.realName }}</span
              ><br />
              <span>身份证：{{ scope.row.idCardNo }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="提交时间" align="center" prop="createTime">
        </el-table-column>
        <el-table-column label="审核状态" align="center"
          ><template slot-scope="scope">
            <el-tag
              type="success"
              effect="plain"
              v-if="scope.row.auditStatus === 1"
              >审核通过</el-tag
            >
            <el-tag
              type="info"
              effect="plain"
              v-if="scope.row.auditStatus === 0"
              >待审核</el-tag
            >
            <el-tag
              type="danger"
              effect="plain"
              v-if="scope.row.auditStatus === -1"
              >审核拒绝</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="账号状态" align="center"
          ><template slot-scope="scope">
            <el-tag type="success" effect="plain" v-if="scope.row.status === 0"
              >正常</el-tag
            >
            <el-tag type="danger" effect="plain" v-if="scope.row.status === 1"
              >异常</el-tag
            >
          </template>
        </el-table-column>
        <!-- <el-table-column label="团队" align="center" prop="teamId" /> -->
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.auditStatus === 1 && scope.row.status === 0"
              size="mini"
              type="text"
              icon="el-icon-warning-outline"
              @click="handleView(scope.row, 1)"
              v-hasPermi="['admin:taskManage:taskuserlist:edit']"
              >异常
            </el-button>
            <el-button
              v-if="scope.row.auditStatus === 0"
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="audit(scope.row, 1)"
              v-hasPermi="['admin:taskManage:taskuserlist:edit']"
              >通过
            </el-button>
            <el-button
              v-if="scope.row.auditStatus === 0"
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="handleView(scope.row, -1)"
              v-hasPermi="['admin:taskManage:taskuserlist:edit']"
              >拒绝
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            <el-tooltip
              :content="scope.row.remark"
              placement="bottom"
              v-if="scope.row.remark"
            >
              <div
                style="
                  width: 100%;
                  white-space: nowrap;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  cursor: pointer;
                "
              >
                {{ scope.row.remark }}
              </div>
            </el-tooltip>
            <!-- <span v-if="!scope.row.content"></span> -->
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totaldetail > 0"
        :total="totaldetail"
        :page.sync="queryParamsdetail.pageNum"
        :limit.sync="queryParamsdetail.pageSize"
        @pagination="getdetailslist"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="outerVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import {
//   getUserUploadTaskList,
//   UserTaskAudit,
//   submitError,
// } from "@/api/admin/userTask";
import {
  creativeOrderList,
  creativeOrderdetail,
  detailAudit,
  submitError,
} from "@/api/admin/devicemanage";
export default {
  name: "taskManage",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      requestUrl: this.$img.requestUrl,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        submitAccount: "",
        userAccount: "",
      },
      queryParamsdetail: {
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      totaldetail: 0,
      loading: false,
      loading2: false,
      UserUploadTaskList: [],
      creativeOrderdetaillist: [],
      form: {},
      open: false,
      outerVisible: false,
      title: "",
      handBt: "",
      resource: "1",
      orderStatusOptions: [
        {
          dictValue: 0,
          dictLabel: "待审核",
        },
        {
          dictValue: 1,
          dictLabel: "通过审核",
        },
        {
          dictValue: -1,
          dictLabel: "拒绝审核",
        },
      ],
    };
  },
  created() {
    this.getList();
  },

  methods: {
    getList() {
      this.loading = true;
      creativeOrderList(this.queryParams).then((response) => {
        this.UserUploadTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 类型字典翻译
    appTypeFormat(row, column) {
      return this.selectDictLabel(this.orderStatusOptions, row.auditStatus);
    },

    details(row) {
      this.queryParamsdetail.creativeOrderId = row.creativeOrderId;
      this.getdetailslist();
    },
    async getdetailslist() {
      await creativeOrderdetail(this.queryParamsdetail).then((response) => {
        this.creativeOrderdetaillist = response.rows;
        this.totaldetail = response.total;
        this.loading2 = false;
        this.outerVisible = true;
      });
    },

    audit(row, index) {
      let self = this;

      this.$confirm(
        "是否确认" + (index == 1 ? "通过" : "拒绝") + "审核?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          detailAudit({
            detailId: row.detailId,
            auditStatus: parseInt(index),
            remark: "",
          }).then((response) => {
            self.msgSuccess(index == 1 ? "已通过" : "已拒绝");
            self.getdetailslist();
          });
        })
        .catch(function () {});
    },

    //审核
    submit() {
      let self = this;
      console.log(self.form);
      this.$refs["formRef"].validate((valid) => {
        if (valid) {
          if (self.form.auditStatus === 1) {
            submitError({
              detailId: self.form.detailId,
              remark: self.form.remark,
            }).then((response) => {
              if (response.code == 200) {
                self.msgSuccess("操作成功");
                self.getdetailslist();
              } else {
                self.form.remark = "";
              }
            });
          } else {
            detailAudit({
              detailId: self.form.detailId,
              auditStatus: -1,
              remark: self.form.remark,
            }).then((response) => {
              if (response.code == 200) {
                self.msgSuccess("操作成功");
                self.getdetailslist();
              } else {
                self.form.remark = "";
              }
            });
          }
          this.open = false;
        } else {
          return false;
        }
      });
    },

    // 取消按钮
    cancel() {
      this.open = false; //地址弹窗
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleView(row, index) {
      this.form = row;
      if (index == -1) {
        this.title = "审核拒绝";
        this.handBt = "拒绝";
      } else {
        this.title = "账号异常";
        this.handBt = "确定";
      }

      this.open = true;
    },
  },
};
</script>
<style scoped lang="scss"></style>
